<#assign module="gasstation"/>

<@override name="header">
<link rel="stylesheet" href="${ctx}/assets/css/form.css">
<link rel="stylesheet" href="${ctx}/assets/css/datetimepicker.css">
</@override>
<@override name="body">

	<div class="row">
		<div class="col-xs-12">
			<ul class="nav nav-tabs">
	            <li><a href="${ctx}/gasstation/edit/${gsid}">基本信息</a></li>
	            <li><a href="${ctx}/gasstation/editGasPrice/${gsid}">油价设置</a></li>
	            <li class="active"><a href="${ctx}/gasstation/paymentsRecord/${gsid}">资金流水</a></li>
	            <li><a href="${ctx}/gasstation/review/${gsid}">油站评价</a></li>
	        </ul>
		</div>
	</div>

	<div class="row margin-top">
		<div class="col-md-12">
			<div class="panel">
			    <div class="panel-body">
    				<form id="submit_form" action="${ctx}/gasstation/savePaymentsRecord" class="form-horizontal" method="post">
		                <input type="hidden" name="gsid" value="${gsid}">
		                <div class="form-group">
		                    <label class="col-sm-2 control-label"><em>*</em>充值/扣款：</label>
		                    <div class="col-sm-3">
		                    	<input class="form-control" id="money" name="money" type="text" required autofocus/>
		                    </div>
		                    <div class="col-sm-5">   
				            	<span id="tip4Desc">本次充值金额,如：100。输入负数表示扣费。0元不生成记录</span>
				            </div>
		                </div>
		                
		               <div class="form-group">
		                    <label class="col-sm-2 control-label">备注：</label>
		                    <div class="col-sm-3">
		                        <textarea class="form-control" cols="20" id="memo" name="memo" rows="2" maxlength="200"></textarea>
		                    </div>
		                    <div class="col-sm-5">   
				            	<span id="tip4Desc">本次充值（扣费）说明，最多输入200个字符<br/>还可输入<span id="leftWords" style="color:red;">200</span>个字符</span>
				            </div>
		                </div>
		                
		                <div class="form-group" style="margin-left:10px;">
			                <label class="col-sm-3 control-label"></label>
			                <@shiro.hasPermission name='membermoney'>
			                <input type="submit" id="submit_button" class="btn btn-primary" value="保存">
			                </@shiro.hasPermission>
			                <input type="button" class="btn btn-default" onclick="window.history.go(-1);" value="返回">
			            </div>
					</form>
        		</div>
			</div>
		</div>
	</div>
	
	<div class="row">
		<div class="col-md-13">
			<div class="panel">
				<div class="panel-body">
					<form class="form-inline" id="SearchForm" method="get">
					    <div class="form-group">
			                <input class="form-control" id="startTime" name="startTime" placeholder="开始时间" readonly="readonly" type="text" value="">
			            </div>
			            <div class="form-group">
			                <input class="form-control" id="endTime" name="endTime" placeholder="结束时间" readonly="readonly" type="text" value="">
			            </div>
			            <div class="form-group">
			                <input type="submit" class="btn btn-default" value="查询">
			            </div>
			            <div class="form-group">
			            	<button type="button" id="export_button" class="pull-right btn btn-primary"><i class="glyphicon glyphicon-save"></i>&nbsp;导出记录</button>
						</div>
					</form>
				</div>
			</div>	
	    </div>	
    </div>
    
    <div class="row">
	   <div class="col-md-12">
	   	  <div class="panel panel-default">
				<table class="table table-hover table-striped">
					<thead>
					<tr style="font-size:14px;">
						<th>时间</th>
						<th>单号</th>
						<th>加油/充值金额</th>
						<th>实收金额</th>
						<th>操作后余额</th>
						<th>类型</th>
						<th>操作人</th>
						<th>备注</th>
					</tr>
					</thead>
				<tbody>
					<#if (page.content)?? >
						<#assign toalRealMoney=0 />
					  	<#list page.content as data>
							<tr>
								<td>${data.created?datetime}</td>
								<td>
									${data.orderNum?if_exists}
								</td>
								<#if (data.rcType==0)>
									<td><span style="color:#00EC00;font-weight:700;">+${data.money?if_exists}</span></td>
									<td><span style="color:#00EC00;font-weight:700;">${data.realMoney?if_exists}</span></td>
									<td><span style="color:#00EC00;font-weight:700;">${data.afterMoney?if_exists}</span></td>
								<#else>
									<#if data.realMoney??>
										<#assign toalRealMoney=toalRealMoney+data.realMoney />
									</#if>
									<td><span style="color:#EA0000;font-weight:700;">${data.money?if_exists}</span></td>
									<td><span style="color:#EA0000;font-weight:700;">${data.realMoney?if_exists}</span></td>
									<td><span style="color:#00EC00;font-weight:700;">${data.afterMoney?if_exists}</span></td>
								</#if>
								<td>
									${data.recordTypeStr?if_exists}
								</td>
								<td>${data.operating?if_exists}</td>
								<td style="max-width:450px;">${data.memo?if_exists}</td>
							</tr>
						</#list>
						<tr>
							<td></td>
							<td></td>
							<td>合计</td>
							<td>${toalRealMoney}</td>
							<td></td>
							<td></td>
							<td></td>
							<td style="max-width:450px;"></td>
						</tr>
					</#if>
				</tbody>
			</table>
			<#if page.totalElements??>
			<ul class="pagination pull-right pagination-sm">
				<li><a>共 ${page.totalElements} 条数据</a></li>
				<@pg.pager items=page.totalElements?number maxPageItems=20 export="currentPageNumber=pageNumber" url="${ctx}/gasstation/paymentsRecord/${gsid}">
					<@pg.param name="startTime" value="${start?string('yyyy-MM-dd HH:mm')}"/>
					<@pg.param name="endTime" value="${end?string('yyyy-MM-dd HH:mm')}"/>
					<@pg.index>
						<@pg.first>
							<li><a href="${pageUrl}">&laquo;</a></li>
						</@pg.first>
						<@pg.prev>
							<li><a href="${pageUrl}">&lsaquo;</a></li>
						</@pg.prev>
						<@pg.pages>
							<#if  currentPageNumber == pageNumber >
								<li class="active"><a href="#">${pageNumber}</a></li>
							<#else>
								<li><a href="${pageUrl}">${pageNumber}</a></li>
							</#if>
						</@pg.pages>
						<@pg.next>
							<li><a href="${pageUrl}">&rsaquo;</a></li>
						</@pg.next>
						<@pg.last>
							<li><a href="${pageUrl}">&raquo;</a></li>
						</@pg.last>
					</@pg.index>
				</@pg.pager>
			</ul>
			</#if>
			</div>
		</div>
	</div>

</@override>
<@override name="footer">

<script src="${ctx}/assets/js/bootstrap-datetimepicker.min.js"></script>
<script src="${ctx}/assets/js/bootstrap-datetimepicker.zh-CN.js"></script>

<script type="text/javascript">
	$(document).ready(function(){
	
		$("#startTime").datetimepicker({ format: 'yyyy-mm-dd HH:ii', language: 'zh-CN', minView: 'hour', pickDate: true, pickTime: false, inputMask: false, autoclose: true });
		$("#endTime").datetimepicker({ format: 'yyyy-mm-dd HH:ii', language: 'zh-CN', minView: 'hour', pickDate: true, pickTime: false, inputMask: false, autoclose: true });
	
	
		$("#memo").keyup(function(){
			$("#leftWords").html(200-$(this).val().length);
		});
		
		$("#submit_form").submit(function(){
			var money=$("#money").val();
			if(money.length>0){
				
				var reg=/^(-?\d+)(.[0-9]{0,2})?$/;
				if(!reg.test(money)){
			       $.scojs_message('无效的金额！', $.scojs_message.TYPE_ERROR);
			       return false;
			    }
			    
			    if(money>1000000){
			    	$.scojs_message('金额过大！', $.scojs_message.TYPE_ERROR);
			    	return false;
			    }
			
				var confirm = $.scojs_confirm({
		          content: "确认要充值"+money+"元吗？",
		          action:function(){
		          	$("#submit_button").attr("disabled",true);
					$.post($("#submit_form").attr("action"),$("#submit_form").serialize(),function(data){
			            if(data.success){
			                window.location.reload(true);
			            }
			            else {
			            	$("#submit_button").attr("disabled",false);
			            	$.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
			            }
				    },'json');
		          }
		        });
		        confirm.show();
			}
			else{
				$.scojs_message('请填写金额！', $.scojs_message.TYPE_ERROR);
			}
			return false;
		});
		
		$('#endTime').change(function(){
			var begin=new Date($('#startTime').val().replace(/-/g,"/"));
	    	var end=new Date($('#endTime').val().replace(/-/g,"/"));
	   		if(begin!=null&&end!=null&&begin-end>0){
  				 $('#endTime').val("");
  				 $.scojs_message("截止日期要在开始日期之后!", $.scojs_message.TYPE_ERROR);
	      	}
	 	});
	 	
		$('#startTime').change(function(){
			var begin=new Date($('#startTime').val().replace(/-/g,"/"));
		 	var end=new Date($('#endTime').val().replace(/-/g,"/"));
		 	if(begin!=null&&end!=null&&begin-end>0){
	  			$('#endTime').val("");
				 $.scojs_message("开始日期要在截止日期之前!", $.scojs_message.TYPE_ERROR);
	      	}
		});
		
		$("#export_button").click(function(){
		
			window.location="${ctx}/gasstation/paymentsRecordExport/${gsid}?startTime="+$("#startTime").val()+"&endTime="+$("#endTime").val()+"";
		});
	});
</script>
</@override>
<@extends name="../layout.ftl"/>